package org.luxor.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.luxor.commons.core.validator.group.AddGroup;
import org.luxor.commons.core.validator.group.UpdateGroup;
import org.luxor.commons.core.web.controller.BaseRestController;
import org.luxor.commons.core.web.data.R;
import org.luxor.commons.jdbc.metadata.PageQuery;
import org.luxor.system.entity.SysUserManageEntity;
import org.luxor.system.service.ISysUserManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;

/**
 * 用户数据权限管理表
 *
 * @author Mark @date 2020-12-29 10:27:13
 */
@RestController
@RequestMapping("/system/sysUserManage")
@Api(tags = "用户数据权限管理表")
public class SysUserManageController extends BaseRestController {

    @Resource
    private ISysUserManageService sysUserManageService;

    @ApiOperation("分页列表")
    @PostMapping("/list")
    public R<IPage<SysUserManageEntity>> list(@RequestBody PageQuery<HashMap> searchPage) {
        IPage<SysUserManageEntity> data = sysUserManageService.page(searchPage.getPage(), searchPage.getSearch());
        return R.ok(data);
    }

    @ApiOperation("详情信息")
    @ApiImplicitParam(name = "id", value = "主键ID", paramType = "path", required = true)
    @GetMapping("/info/{id}")
    public R<SysUserManageEntity> info(@PathVariable("id") Long id) {
        SysUserManageEntity sysUserManage = sysUserManageService.getById(id);
        return R.ok(sysUserManage);
    }

    @ApiOperation("保存")
    @PostMapping("/save")
    public R<SysUserManageEntity> save(@Validated(AddGroup.class) @RequestBody SysUserManageEntity sysUserManage) {
        sysUserManageService.save(sysUserManage);
        return R.ok(sysUserManage);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public R<SysUserManageEntity> update(@Validated(UpdateGroup.class) @RequestBody SysUserManageEntity sysUserManage) {
        sysUserManageService.updateById(sysUserManage);
        return R.ok(sysUserManage);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        sysUserManageService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
